package com.cvit.service;

import java.io.InputStream;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import com.cvit.dao.ExaminationtableMapper;
import com.cvit.model.Examinationtable;
import com.cvit.utils.ExcelUtil;
import com.cvit.utils.Utils;

@Service
public class ExaminationtableService {
	@Autowired
	ExaminationtableMapper examinationtableMapper;

	/**
	 * 根据考生号查询Ws
	 * */
	public List<Examinationtable> getByEamineeId(String eamineeId) {
		List<Examinationtable> examinationtables = examinationtableMapper.selectByEamineeId(eamineeId);
		return examinationtables;
	}
	
	/**
	 * 按学生号查询准考证信息 Ws
	 * */
	public List<Examinationtable> getEamineeId(Examinationtable examinationtable) {
		List<Examinationtable> examinationtables = examinationtableMapper.selectEamineeId(examinationtable);
		return examinationtables;
	}
	/**
	 * 按身份证号查询准考证信息 Ws
	 * */
	public List<Examinationtable> getCardId(Examinationtable examinationtable) {
		List<Examinationtable> examinationtables = examinationtableMapper.selectcardId(examinationtable);
		return examinationtables;
	}
	
	/**
	 * 查询考场表单（包含学生表信息）
	 * */
	public List<Examinationtable> getExaminationtable() {
		// TODO Auto-generated method stub
		List<Examinationtable> examinationtable = examinationtableMapper.selectByExample(null);
		return examinationtable; 
	}
	
	/**
	 * 根据考生号(eaminee_id)、身份证号(card_id)、准考号(student_number)查询
	 * */
	public List<Examinationtable> getExaminationtableBy(Examinationtable examinationtable) {
		// TODO Auto-generated method stub
		List<Examinationtable> examinationtables = examinationtableMapper.selectExaminationtableBy(examinationtable);
		return examinationtables;
	}
	/**
	 * 根据eamineeId（考生号）查询 （boolean）
	 * */
	public boolean getExaminationtableById(String eamineeId){
		List<Examinationtable> examinationtable = examinationtableMapper.selectByEamineetableId(eamineeId);
			return Utils.isNull(examinationtable);
	}
	
	/**
	 * 导入Excel
	 * */
	public void importExcelInfo(InputStream in, MultipartFile file) throws Exception{
	    List<List<Object>> listob = ExcelUtil.getBankListByExcel(in,file.getOriginalFilename()); 
	    //遍历listob数据，把数据放到List中
	    for (int i = 0; i < listob.size(); i++) {
	        List<Object> ob = listob.get(i);
	        Examinationtable examinationtable = new Examinationtable();
	        examinationtable.setId(Utils.getsUUID());
	        //设置编号  
	        //通过遍历实现把每一列封装成一个model中，再把所有的model用List集合装载
	        examinationtable.setExamineNumber(String.valueOf(ob.get(0)));//审核序号
	        examinationtable.setEamineeId(String.valueOf(ob.get(1)));//考生号
	        examinationtable.setName(String.valueOf(ob.get(2)));//姓名
	        examinationtable.setGender(String.valueOf(ob.get(3)));//性别
	        examinationtable.setCardId(String.valueOf(ob.get(4)));//身份证号
	        examinationtable.setStudentNumber(String.valueOf(ob.get(5)));//准考证号
	        examinationtable.setOverall(String.valueOf(ob.get(10)));//考试方式
	        examinationtable.setExaminationRoom(String.valueOf(ob.get(9)));//考场
	        examinationtable.setExaminationPlace(String.valueOf(ob.get(8)));//考试地点
	        examinationtable.setExaminationTime(String.valueOf(ob.get(6)));//考试时间
	        examinationtable.setTestTime(String.valueOf(ob.get(7)));//考试时长
	        examinationtableMapper.insert(examinationtable);
	    }  
	}
	
	public List<Examinationtable> selectTicketAll(){
		List<Examinationtable> examinationtable = examinationtableMapper.selectByExample(null);
		return examinationtable;
	}
	
	

}
